package com.example.controller;

import com.example.entity.RestBean;
import com.example.entity.singerAndGame.Singer;
import com.example.service.SingerService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/api/singer")
public class SingerController {
    @Resource
    SingerService service;

    @GetMapping("/all")
    public RestBean<List<Singer>> all() {
        return RestBean.success(service.getSingerList());
    }

    @PostMapping("/sid")
    public RestBean<Singer> one(int sid) {
        return RestBean.success(service.getSingerBySid(sid));
    }

    @PostMapping("/add")
    public RestBean<String> add(@RequestParam("file") MultipartFile file, Singer singer) {
        String s = service.addSinger(file, singer);
        if (s == null)
            return RestBean.success("歌手新增成功");
        else
            return RestBean.failure(400, s);
    }

    @PostMapping("/update")
    public RestBean<String> update(@RequestParam("file") MultipartFile file, Singer singer) {
        String s = service.updateSingerBySid(file, singer);
        if (s == null)
            return RestBean.success("歌手修改成功");
        else
            return RestBean.failure(400, s);
    }

    @PostMapping("/delete")
    public RestBean<String> delete(int sid) {
        String s = service.deleteSingerBySid(sid);
        if (s == null)
            return RestBean.success("删除成功");
        else
            return RestBean.failure(400, s);
    }

}
